package com.hzncc.flowable_diboot.delivery.dto;

import com.diboot.core.binding.query.BindQuery;
import com.diboot.core.binding.query.Comparison;
import com.diboot.iam.entity.IamOrg;
import com.diboot.iam.entity.IamUser;
import com.hzncc.flowable_diboot.delivery.entity.DeliveryRegister;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 发货登记 DTO定义
 *
 * @author MyName
 * @version 1.0
 * @date 2024-10-12
 * Copyright © MyCorp
 */
@Getter
@Setter
@Accessors(chain = true)
public class DeliveryRegisterDTO extends DeliveryRegister {
    private static final long serialVersionUID = 1856385984821902884L;

    @BindQuery(ignore = true)
    private String mustSapContractCode;

    /**
     * SAP发货日期
     */
    @BindQuery(comparison = Comparison.GE)
    private LocalDateTime sapDeliveryTime;
    /**
     * SAP发货日期 起始
     */
    @BindQuery(comparison = Comparison.GE, column = "sap_delivery_time")
    private LocalDate sapDeliveryTimeBegin;

    /**
     * SAP发货日期 截止
     */
    @BindQuery(comparison = Comparison.LT, column = "sap_delivery_time")
    private LocalDate sapDeliveryTimeEnd;
    /**
     * 实际发货时间
     */
    @BindQuery(comparison = Comparison.GE)
    private LocalDateTime deliveryTime;
    /**
     * 实际发货时间 起始
     */
    @BindQuery(comparison = Comparison.GE, column = "delivery_time")
    private LocalDate deliveryTimeBegin;

    /**
     * 实际发货时间 截止
     */
    @BindQuery(comparison = Comparison.LT, column = "delivery_time")
    private LocalDate deliveryTimeEnd;
    /**
     * 计划发货时间
     */
    @BindQuery(comparison = Comparison.GE)
    private LocalDateTime planDeliveryTime;
    /**
     * 计划发货时间 起始
     */
    @BindQuery(comparison = Comparison.GE, column = "plan_delivery_time")
    private LocalDate planDeliveryTimeBegin;

    /**
     * 计划发货时间 截止
     */
    @BindQuery(comparison = Comparison.LT, column = "plan_delivery_time")
    private LocalDate planDeliveryTimeEnd;
    /**
     * 件数 起始
     */
    @BindQuery(comparison = Comparison.GE, column = "quantity")
    private Long quantityBegin;

    /**
     * 件数 截止
     */
    @BindQuery(comparison = Comparison.LE, column = "quantity")
    private Long quantityEnd;
    /**
     * 重量 起始
     */
    @BindQuery(comparison = Comparison.GE, column = "weight")
    private BigDecimal weightBegin;

    /**
     * 重量 截止
     */
    @BindQuery(comparison = Comparison.LE, column = "weight")
    private BigDecimal weightEnd;
    /**
     * 开票时间
     */
    @BindQuery(comparison = Comparison.GE)
    private LocalDateTime invoiceTime;
    /**
     * 开票时间 起始
     */
    @BindQuery(comparison = Comparison.GE, column = "invoice_time")
    private LocalDate invoiceTimeBegin;

    /**
     * 开票时间 截止
     */
    @BindQuery(comparison = Comparison.LT, column = "invoice_time")
    private LocalDate invoiceTimeEnd;
    /**
     * 预计开票时间
     */
    @BindQuery(comparison = Comparison.GE)
    private LocalDateTime planInvoiceTime;
    /**
     * 预计开票时间 起始
     */
    @BindQuery(comparison = Comparison.GE, column = "plan_invoice_time")
    private LocalDate planInvoiceTimeBegin;

    /**
     * 预计开票时间 截止
     */
    @BindQuery(comparison = Comparison.LT, column = "plan_invoice_time")
    private LocalDate planInvoiceTimeEnd;
    /**
     * 创建时间
     */
    @BindQuery(comparison = Comparison.GE)
    private LocalDateTime createTime;
    /**
     * 创建时间 起始
     */
    @BindQuery(comparison = Comparison.GE, column = "create_time")
    private LocalDate createTimeBegin;

    /**
     * 创建时间 截止
     */
    @BindQuery(comparison = Comparison.LT, column = "create_time")
    private LocalDate createTimeEnd;
    /**
     * 更新时间
     */
    @BindQuery(comparison = Comparison.GE)
    private LocalDateTime updateTime;
    /**
     * 更新时间 起始
     */
    @BindQuery(comparison = Comparison.GE, column = "update_time")
    private LocalDate updateTimeBegin;

    /**
     * 更新时间 截止
     */
    @BindQuery(comparison = Comparison.LT, column = "update_time")
    private LocalDate updateTimeEnd;

    /**
     * 合同编号
     */
    private String contractCode;

    public LocalDate getSapDeliveryTimeEnd() {
        if (getSapDeliveryTime() != null) {
            return getSapDeliveryTime().plusDays(1).toLocalDate();
        }
        if (sapDeliveryTimeEnd != null) {
            return sapDeliveryTimeEnd.plusDays(1);
        }
        return null;
    }

    public LocalDate getDeliveryTimeEnd() {
        if (getDeliveryTime() != null) {
            return getDeliveryTime().plusDays(1).toLocalDate();
        }
        if (deliveryTimeEnd != null) {
            return deliveryTimeEnd.plusDays(1);
        }
        return null;
    }

    public LocalDate getPlanDeliveryTimeEnd() {
        if (getPlanDeliveryTime() != null) {
            return getPlanDeliveryTime().plusDays(1).toLocalDate();
        }
        if (planDeliveryTimeEnd != null) {
            return planDeliveryTimeEnd.plusDays(1);
        }
        return null;
    }

    public LocalDate getInvoiceTimeEnd() {
        if (getInvoiceTime() != null) {
            return getInvoiceTime().plusDays(1).toLocalDate();
        }
        if (invoiceTimeEnd != null) {
            return invoiceTimeEnd.plusDays(1);
        }
        return null;
    }

    public LocalDate getPlanInvoiceTimeEnd() {
        if (getPlanInvoiceTime() != null) {
            return getPlanInvoiceTime().plusDays(1).toLocalDate();
        }
        if (planInvoiceTimeEnd != null) {
            return planInvoiceTimeEnd.plusDays(1);
        }
        return null;
    }

    public LocalDate getCreateTimeEnd() {
        if (getCreateTime() != null) {
            return getCreateTime().plusDays(1).toLocalDate();
        }
        if (createTimeEnd != null) {
            return createTimeEnd.plusDays(1);
        }
        return null;
    }

    public LocalDate getUpdateTimeEnd() {
        if (getUpdateTime() != null) {
            return getUpdateTime().plusDays(1).toLocalDate();
        }
        if (updateTimeEnd != null) {
            return updateTimeEnd.plusDays(1);
        }
        return null;
    }

}